package com.example.administrator.liveapp.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.administrator.liveapp.ApplicationUtils;
import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.Xutils3.MyCallBack;
import com.example.administrator.liveapp.Xutils3.XUtils;
import com.example.administrator.liveapp.utils.AppUrl;

import java.util.HashMap;
import java.util.Map;

/**
 * 商品退款activity
 */

public class RefundReasonActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText comment;//退款理由
    private Button submit;//退款
    private ImageView secondary_return;//返回
    Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refund_reason);
        initView();
    }

    private void initView() {
        intent = getIntent();
        comment = (EditText) findViewById(R.id.comment);
        submit = (Button) findViewById(R.id.submit);
        submit.setOnClickListener(this);
        secondary_return = (ImageView) findViewById(R.id.secondary_return);
        secondary_return.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.secondary_return:
                finish();
                break;
            case R.id.submit:
                String url = AppUrl.URL+AppUrl.bookRefund;
                Map<String,String> map = new HashMap<>();
                map.put("refundUid", ApplicationUtils.getInstance().loginBean.getConsumerid());
                map.put("goodsOrder",intent.getStringExtra("goodsOrder"));
                map.put("orderPrice",intent.getStringExtra("orderPrice"));
                map.put("refundReason",comment.getText().toString());
                XUtils.Get(url,map,new MyCallBack<String>(){
                    @Override
                    public void onSuccess(String result) {
                        super.onSuccess(result);
                        Toast.makeText(RefundReasonActivity.this, "退款申请已提交", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        super.onError(ex, isOnCallback);
                        Toast.makeText(RefundReasonActivity.this, ex.getMessage()+"退款申请失败", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFinished() {
                        super.onFinished();
                    }
                });
                break;
        }
    }
}
